﻿using System.Collections.Generic;
using System.Drawing;
using WindowsInput;
using WindowsInput.Native;


namespace FeiYang
{
    public static class 键鼠_
    {
        private static IKeyboardSimulator _键盘;
        private static IMouseSimulator _鼠标;
        private static double K;
        private static double G;

        static 键鼠_()
        {
            var 键鼠模拟器 = new InputSimulator();
            _键盘 = 键鼠模拟器.Keyboard;
            _鼠标 = 键鼠模拟器.Mouse;
            K = System.Windows.SystemParameters.PrimaryScreenWidth;
            G = System.Windows.SystemParameters.PrimaryScreenHeight;
        }
        public static void 按下(VirtualKeyCode k)
        {
            _键盘.KeyDown(k);
        }
        public static void 松开(VirtualKeyCode k)
        {
            _键盘.KeyUp(k);
        }
        public static void 按键(VirtualKeyCode k)
        {
            _键盘.KeyPress(k);
        }
        public static void 按键(VirtualKeyCode[] ks)
        {
            _键盘.KeyPress(ks);
        }
        public static void 组合按键(IEnumerable<VirtualKeyCode> modifierKeyCodes, VirtualKeyCode keyCode)
        {
            _键盘.ModifiedKeyStroke(modifierKeyCodes, keyCode);
        }
        public static void 组合按键(VirtualKeyCode modifierKey, IEnumerable<VirtualKeyCode> keyCodes)
        {
            _键盘.ModifiedKeyStroke(modifierKey, keyCodes);
        }
        public static void 组合按键(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode)
        {
            _键盘.ModifiedKeyStroke(modifierKeyCode, keyCode);
        }
        public static void 输入文本(string text)
        {
            _键盘.TextEntry(text);
        }
        public static void 移动鼠标(Point p)
        {
            移动鼠标(p.X, p.Y);
        }
        public static void 移动鼠标(int x, int y)
        {
            _鼠标.MoveMouseToPositionOnVirtualDesktop(x * 0xFFFF / K, y * 0xFFFF / G);
        }
        public static void 左键按下()
        {
            _鼠标.LeftButtonDown();
        }
        public static void 左键抬起()
        {
            _鼠标.LeftButtonUp();
        }
        public static void 左键单击()
        {
            _鼠标.LeftButtonClick();
        }

        public static void 左键单击(Point p)
        {
            左键单击(p.X, p.Y);
        }

        public static void 左键单击(Point p, int 延迟)
        {
            左键单击(p.X, p.Y, 延迟);
        }
        public static void 左键单击(int x, int y, int 延迟)
        {
            移动鼠标(x, y);
            _鼠标.Sleep(50 + 延迟);
            左键按下();
            _鼠标.Sleep(50);
            左键抬起();
        }
        public static void 左键单击(int x, int y)
        {
            移动鼠标(x, y);
            _鼠标.Sleep(50);
            左键按下();
            _鼠标.Sleep(50);
            左键抬起();
        }

        public static void 左键双击(int x, int y)
        {
            左键单击(x, y);
            _鼠标.Sleep(50);
            左键单击(x, y);
        }
        public static void 左键双击(Point p)
        {
            左键双击(p.X, p.Y);
        }
        public static void 左键双击()
        {
            _鼠标.LeftButtonDoubleClick();
        }
        public static void 右键按下()
        {
            _鼠标.RightButtonDown();
        }
        public static void 右键抬起()
        {
            _鼠标.RightButtonUp();
        }

        public static void 右键单击(Point p)
        {
            右键单击(p.X, p.Y);
        }
        public static void 右键单击(int x, int y)
        {
            移动鼠标(x, y);
            _鼠标.Sleep(50);
            右键按下();
            _鼠标.Sleep(50);
            右键抬起();
        }
        public static void 中键按下()
        {
            _鼠标.MiddleButtonDown();
        }
        public static void 中键抬起()
        {
            _鼠标.MiddleButtonUp();
        }
        public static void 中键单击()
        {
            _鼠标.MiddleButtonClick();
        }
        public static void 中键双击()
        {
            _鼠标.MiddleButtonDoubleClick();
        }
        public static void 滚动滚轮(int 滚动量)
        {
            _鼠标.VerticalScroll(滚动量);
        }
    }
}